import java.util.ArrayList;
import java.util.Scanner;

public class HW_6_findFourSame {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        Scanner sc=new Scanner(System.in);
        System.out.println("---是否连续出现四次---");
        System.out.println("你要输入数字的个数:");
        int num=sc.nextInt();
        System.out.println("请输入数字:");
        for (int i = 0; i < num; i++) {
            list.add(sc.nextInt());
        }
        int flag=0;
        for (int i = 0; i < list.size(); i++) {
            if (isRepeatFour(list, list.get(i))) {
                System.out.println("存在四个连续相同的数:"+list.get(i));
                flag=1;
                break;
            }
        }
        if(flag==0){
            System.out.println("不存在四个连续相同的数");
        }
    }
    //判断数字是否连续出现了四次
    public static boolean isRepeatFour(ArrayList<Integer> list,int num){
        int count = 0;
        for (int i = 0; i < list.size(); i++) {
            if (count>=4){
                return true;
            }
            if (list.get(i) == num) {
                count++;
            } else {
                count = 0;
            }
        }
        return false;
    }
}
